package cn.edu.neusoft.yuejian.activity;

import android.graphics.Paint;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.yuejian.R;
import cn.edu.neusoft.yuejian.frgment.BsFragment;
import cn.edu.neusoft.yuejian.frgment.DsFragment;
import cn.edu.neusoft.yuejian.frgment.DsKtFragment;
import cn.edu.neusoft.yuejian.frgment.DsWtFragment;
import cn.edu.neusoft.yuejian.frgment.HdFragment;

public class DsInfoActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView js,dz,ds_kt,ds_wz;
    private ImageView pic;
    private DsKtFragment DsKtFragment;
    private DsWtFragment DsWtFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ds_info);
        initViews();
        getdate();
        setSelect(0);
        initEvent();

    }
    private void initViews() {
        js=(TextView)findViewById(R.id.ds_info_js);
        dz=(TextView)findViewById(R.id.ds_info_dz);
        ds_kt=(TextView)findViewById(R.id.ds_kt);
        ds_wz=(TextView)findViewById(R.id.ds_wt);
        pic=(ImageView)findViewById(R.id.ds_info_pic);
    }
    private void getdate() {
        Bundle intent=getIntent().getExtras();
        String id = intent.getString("id");
        String Club_name = intent.getString("Club_name");
        String City_name = intent.getString("City_name");
        String Province_name = intent.getString("Province_name");
        String Introduction = intent.getString("Introduction");
        String Thumb=intent.getString("Thumb");
        js.setText(Introduction);dz.setText(Club_name+"("+Province_name+City_name+")");
        Picasso.with(DsInfoActivity.this)
                .load("http://172.24.10.175/workout/Uploads/"+Thumb)
                .error(R.drawable.wu)
                .into(pic);

    }
    private void initEvent()
    {
        ds_kt.setOnClickListener(this);
        ds_wz.setOnClickListener(this);

    }
    private void setSelect(int i)
    {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        hideFragment(transaction);

        switch (i)
        {
            case 0:
                if (DsKtFragment == null)
                {
                    DsKtFragment = new DsKtFragment();
                    transaction.add(R.id.fragment_ds, DsKtFragment);
                } else
                {
                    transaction.show(DsKtFragment);
                }

                ds_kt.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
                ds_wz.getPaint().setFlags(0);
                break;
            case 1:
                if (DsWtFragment == null)
                {
                    DsWtFragment = new DsWtFragment();
                    transaction.add(R.id.fragment_ds, DsWtFragment);
                } else
                {
                    transaction.show(DsWtFragment);

                }

                ds_wz.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
                ds_kt.getPaint().setFlags(0);
                break;
            default:
                break;
        }

        transaction.commit();
    }

    private void hideFragment(FragmentTransaction transaction)
    {
        if (DsKtFragment != null)
        {
            transaction.hide(DsKtFragment);
        }
        if (DsWtFragment != null)
        {
            transaction.hide(DsWtFragment);
        }

    }


    @Override
    public void onClick(View v) {
        //resets();
        switch (v.getId())
        {
            case R.id.ds_kt:
                setSelect(0);
                break;
            case R.id.ds_wt:
                setSelect(1);
                break;

            default:
                break;
        }
    }

//    private void resets() {
//        ds_wz.getPaint().setFlags(0);
//        ds_kt.getPaint().setFlags(0);
//    }
}
